#!/usr/bin/perl -w
  
use strict;
  use CGI;
  use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
use lib qw( /var/pwneth/htdocs/rpg/lib );
use RedMoon::Account;
use RedMoon::Core;
use RedMoon::Utils;

my $q = new CGI;
my $pwn = RedMoon::Account->new;
my $game = RedMoon::Core->new;
my $utils = RedMoon::Utils->new;

my($acct_id, $session);

	my $usr = $q->param('usr');
	my $pwd = $q->param('pwd');
	my $logout = $q->param('action')||"";

	if($usr && $pwd)
	{
		($acct_id,$session) = $pwn->Auth($usr,$pwd);
	}
	else
	{
		($acct_id,$session) = $pwn->isLoggedIn($acct_id);
	}

		if($logout eq 'logout')
		{
			$pwn->destroySesh($acct_id);
		}

		if($acct_id && $session)
		{
			print $q->header;
		}
		else
		{
			print $q->header;
			print "<script type='text/javascript'>
					<!--
					window.location = \"./login.pl\"
					//-->
					</script>";
		}
  
my($html,$theme) = $utils->readTemplate('adm/index');
print $q->start_html( -style => { src => "themes/$theme/style.css" } );

	my $menu = $game->menu($acct_id);
	my $content = '';

	$html =~ s/\$MENU\$/$menu/g;
	$html =~ s/\$CONTENT\$/$content/g;

print $html;
